//org.jackysoft.workflow.bizness.util.CheckActionStatusCondition
package org.jackysoft.workflow;

import java.util.Map;

import org.jackysoft.entity.OsVariable;
import org.jackysoft.entity.WorkflowRunner;
import org.jackysoft.service.OsVariableService;

/**
 * <blockquote> 检查用户动作的状态,每一个步骤回退回来后都有对应的状态 来限制action对起草者可见,这个条件主要用来检查当前
 * 给定的status是否和用户当前所处的status是否同一 状态 </blockquote>
 * 
 * */
public class CheckActionStatusCondition implements Condition {

	@Override
	public boolean passesCondition(Map<String, Object> transientVars,
			Map<String, String> args, OsVariableService vservice)
			throws WorkflowException {
		String status = args.get(TechActionStatus.STATUSNAME
				.toString());
		if (status == null)
			throw new IllegalArgumentException("未设置适当的参数 ["
					+ TechActionStatus.STATUSNAME + "]");
		WorkflowRunner entry = (WorkflowRunner) transientVars.get("entry");
		OsVariable wv =  vservice.findOneByName(entry.getId(),TechActionStatus.STATUSNAME.toString());
		if (wv == null)
			return false;
		else {
			String ts = wv.getValue();
			return status.equals(ts);
		}
	}

}
